package org.ssm.controller;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.ssm.pojo.Emp;
import org.ssm.service.IEmpService;

import java.util.List;

@Controller
@RequestMapping("/emp")
public class EmpController {
    @Autowired
    private IEmpService empService;

    public void setEmpService(IEmpService empService) {
        this.empService = empService;
    }

    @RequestMapping("/list")
    public String list(Model model){
        List<Emp> empList =   empService.findAll();
        model.addAttribute("list",empList);
        return  "list";
    }

    @RequestMapping("/addForm")
    public String addForm(){
        return "add";
    }

    @RequestMapping("/add")
    public String add(Emp emp){
        empService.saveEmp(emp);
        return "redirect:/emp/list";
    }

    @RequestMapping("/find")
    public String findEmp(Integer empno,Model model){
        Emp emp = empService.findEmp(empno);
        model.addAttribute("emp",emp);
        return "forward:/WEB-INF/add.jsp";
    }

    @RequestMapping("/remove")
    public String remove(Integer empno){
        empService.removeEmp(empno);
        return "redirect:/emp/list";
    }

    @RequestMapping("/modify")
    public String modify(Emp emp){
        empService.modifyEmp(emp);
        return "redirect:/emp/list";
    }


}
